package com.lczyfy.idcp.common.utils;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by jw on 2016/11/19.
 * 返回接口统一返回map帮助类
 */
public class ApiResultUtils {

    private static final boolean SUCCESS = true;
    private static final String SUCCESS_MESSAGE = MsgCodeHelper.MG010101;
    private static final String SUCCESS_MSGCODE = "MG010101";

    private static final boolean FALSE = false;
    private static final String FALSE_MESSAGE = MsgCodeHelper.MG010102;
    private static final String FALSE_MSGCODE = "MG010102";

    public static Map<String, Object> initMap(boolean success, String message, String msgCode) {
        Map<String, Object> baseMap = new HashMap<String, Object>();
        //设置默认值
        //其实只需要 status、msg、data
        baseMap.put("success", success);
        baseMap.put("message", message);
        baseMap.put("msgCode", msgCode);
        //设置其余字段
        baseMap.put("totalPages", "");
        baseMap.put("currentPage", "");
        baseMap.put("totalRecords", "");
        baseMap.put("sort", "");
        baseMap.put("order", "");
        return baseMap;
    }

    //返回所有默认字段
    public static Map<String, Object> getBaseMapSuccess() {
        return getBaseMap(SUCCESS, SUCCESS_MESSAGE, SUCCESS_MSGCODE);
    }

    public static Map<String, Object> getBaseMapFalse() {
        return getBaseMap(FALSE, FALSE_MESSAGE, FALSE_MSGCODE);
    }

    public static Map<String, Object> getBaseMapFalse(String message, String msgCode) {
        return getBaseMap(FALSE, message, msgCode);
    }

    public static Map<String, Object> getBaseMapSuccess(String message, String msgCode) {
        return getBaseMap(SUCCESS, message, msgCode);
    }

    public static Map<String, Object> getBaseMap(boolean result, String message, String msgCode) {
        return initMap(result, message, msgCode);
    }

	public static boolean getSuccess() {
		return SUCCESS;
	}

	public static String getSuccessMessage() {
		return SUCCESS_MESSAGE;
	}

	public static String getSuccessMsgcode() {
		return SUCCESS_MSGCODE;
	}

	public static boolean getFalse() {
		return FALSE;
	}

	public static String getFalseMessage() {
		return FALSE_MESSAGE;
	}

	public static String getFalseMsgcode() {
		return FALSE_MSGCODE;
	}
    
    
    
    //返回需求字段值
//    public static Map<String, Object> getBaseMap(String... keys){
//        initMap();
//        Map<String, Object> requiredMap = new HashMap<String, Object>();
//        //设置默认值
//        requiredMap.put("success","yes");
//        requiredMap.put("message",MsgCodeHelper.MG010101);
//        requiredMap.put("msgCode","MG010101");
//        for (String key : keys){
//            if (!(key.equals("") || key == null)){
//                if (baseMap.entrySet().toString().contains(key)){
//                    System.out.print(key);
//                    requiredMap.put(key,"");
//                }
//            }
//
//        }
//        return requiredMap;
//    }

}
